package com.xii.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xii.constant.MessageConstant;
import com.xii.entity.Result;
import com.xii.service.ReportService;
import com.xii.service.SetmealService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 报表接口
 *
 * @return
 * @author  wangxihao
 * @email wangxh0108@163.com
**/
@Controller
@RequestMapping("/report")
public class ReportController {
    @Reference
    private ReportService reportService;
    @Reference
    private SetmealService setmealService;



    /**
     * 会员图
     * @return
     */
    @RequestMapping("/getMemberReport")
    @ResponseBody
    public Result getMemberReport() {
        try {
            Map<String,Object> memberReport = reportService.getMemberReport();
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,memberReport);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }

    /**
     * 套餐图
     * @return
     */
    @RequestMapping("/getSetmealReport")
    @ResponseBody
    public Result getSetmealReport(){
        List<Map<String,Object>> list = setmealService.findSetmealCount();
        Map<String,Object> map = new HashMap();
        map.put("setmealCount",list);
        List<String> setmealNames = new ArrayList<>();
        for(Map<String,Object> m:list){
            String name = (String)m.get("name");
            setmealNames.add(name);
        }
        map.put("setmealNames",setmealNames);
        return new Result(true,MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,map);
    }

    //运营数据统计
    @RequestMapping("/getBusinessReportData")
    @ResponseBody
    public Result getBusinessReportData(){
        try {
            Map<String,Object> map = reportService.getBusinessReportData();
            return new Result(true,MessageConstant.GET_BUSINESS_REPORT_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
    }



}
